package com.ss.android.newmedia.feedback;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.ProgressBar;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.common.utility.collection.WeakHandler.Callback;
import com.ss.android.article.browser.R;
import com.ss.android.common.app.AbsFragment;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.image.loader.LargeImageLoader;
import com.ss.android.image.model.ImageInfo;
import com.ss.android.image.n;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public final class k extends AbsFragment implements Callback, o {
    boolean a;
    private Context b;
    private List c;
    private WeakHandler d;
    private int e;
    private boolean f;
    private h g;
    private String h;
    private ListView i;
    private ProgressBar j;

    public k() {

        this.c = new ArrayList();
        this.d = new WeakHandler(((Callback) this));
        this.f = false;
        this.a = false;
    }

    public final void a(String arg7, String arg8, Bitmap arg9) {
        if (this.isViewValid()) {
            FragmentActivity v1 = this.getActivity();
            if (((v1 instanceof FeedbackActivity)) && (((FeedbackActivity) v1).isViewValid()) && !android.support.design.a.isTextEmpty(arg7)) {
                if (((FeedbackActivity) v1).d == null) {
                    ((FeedbackActivity) v1).d = new n(((Context) v1), ((FeedbackActivity) v1).f);
                    ((FeedbackActivity) v1).e = new LargeImageLoader(((Context) v1), ((FeedbackActivity) v1).g, ((FeedbackActivity) v1).f, ((FeedbackActivity) v1).d, ((FeedbackActivity) v1).d);
                    ((FeedbackActivity) v1).d.b = ((FeedbackActivity) v1).e;
                }

                if (((FeedbackActivity) v1).d.isShowing()) {
                    return;
                }

                n v0 = ((FeedbackActivity) v1).d;
                ArrayList v2 = new ArrayList();
                if (arg7 != null) {
                    ((List) v2).add(new ImageInfo(arg7, arg8));
                }

                v0.a(((List) v2), 0);
                if (arg9 != null && !android.support.design.a.isTextEmpty(arg7)) {
                    v0.c.put(arg7, arg9);
                }

                ((FeedbackActivity) v1).d.show();
            }
        }
    }

    public final void handleMsg(Message message) {
        ArrayList v1_2;
        Object v1_1;
        List v4;
        int v13 = 8;
        int v12 = 5;
        int v3 = 4;
        int v9 = 1;
        if ((this.isViewValid()) && ((message.obj instanceof com.ss.android.newmedia.feedback.n))) {
            Object v0 = message.obj;
            if ((((long) this.e)) == ((com.ss.android.newmedia.feedback.n) v0).e) {
                if (message.what == 11) {
                    if (message.arg1 != 19 || (this.c.isEmpty())) {
                        UIUtils.showImageToast(this.b, R.drawable.close_popup_textpage, this.getString(TTUtils.a(message.arg1)));
                    }

                    this.f = false;
                    this.j.setVisibility(v13);
                } else {
                    if (((com.ss.android.newmedia.feedback.n) v0).f == 3) {
                        List v1 = this.c;
                        v4 = ((com.ss.android.newmedia.feedback.n) v0).h;
                        ArrayList v2 = new ArrayList();
                        if (v1 == null || v1.size() <= 0) {
                            ((List) v2).addAll(((Collection) v4));
                            label_46:
                            v1_2 = v2;
                        } else {
                            if (v4 != null && v4.size() > 0) {
                                HashMap v5 = new HashMap();
                                Iterator v6 = v1.iterator();
                                while (v6.hasNext()) {
                                    v1_1 = v6.next();
                                    v5.put(Long.valueOf(((com.ss.android.newmedia.feedback.g) v1_1).a), v1_1);
                                }

                                Iterator v4_1 = v4.iterator();
                                while (true) {
                                    if (v4_1.hasNext()) {
                                        v1_1 = v4_1.next();
                                        if (v5.containsKey(Long.valueOf(((com.ss.android.newmedia.feedback.g) v1_1).a))) {
                                            continue;
                                        }

                                        ((List) v2).add(v1_1);
                                        continue;
                                    } else {
                                        v1_2 = v2;
                                        break;
                                    }
                                }
                            } else {
                                v1_2 = v2;
                            }
                        }
                        this.c.addAll(((Collection) v1_2));
                    } else {
                        if (((com.ss.android.newmedia.feedback.n) v0).f != v3 && ((com.ss.android.newmedia.feedback.n) v0).f != v12 && ((com.ss.android.newmedia.feedback.n) v0).f != 1) {
                            return;
                        }

                        if (((com.ss.android.newmedia.feedback.n) v0).f == 1) {
                            com.ss.android.newmedia.feedback.a.a().b = System.currentTimeMillis();
                        }

                        this.c.clear();
                        this.c.addAll(((com.ss.android.newmedia.feedback.n) v0).h);
                    }

                    h v1_3 = this.g;
                    List v2_1 = this.c;
                    v4 = ((com.ss.android.newmedia.feedback.n) v0).i;
                    v1_3.a.clear();
                    if (v4 != null && v4.size() > 0) {
                        v1_3.a.addAll(((Collection) v4));
                    }

                    if (v2_1 != null && v2_1.size() > 0) {
                        v1_3.a.addAll(((Collection) v2_1));
                    }

                    v1_3.notifyDataSetChanged();
                    this.i.setSelection(this.g.getCount());
                    this.f = false;
                    this.j.setVisibility(v13);
                    if (((com.ss.android.newmedia.feedback.n) v0).f != v12) {
                        return;
                    }

                    if (NetworkUtils.isNetworkAvailable(this.b)) {
                        ++this.e;
                        this.f = true;
                        if (System.currentTimeMillis() - com.ss.android.newmedia.feedback.a.a().b <= 864000000) {
                            v9 = v3;
                        }

                        new j(this.d, this.b, new com.ss.android.newmedia.feedback.n(this.h, 0, 0, -1, ((long) this.e), v9)).start();
                        return;
                    }

                    UIUtils.showImageToast(this.b, R.drawable.close_popup_textpage, R.string.ss_error_no_connections);
                }
            }
        }
    }

    public final void onActivityCreated(Bundle arg11) {
        long v2 = 0;
        super.onActivityCreated(arg11);
        Bundle v0 = this.getArguments();
        if (v0 != null) {
            this.h = v0.getString("key_appkey");
        }

        this.b = this.getActivity();
        this.g = new h(this.b, ((o) this));
        this.registerLifeCycleMonitor(this.g);
        this.i.setAdapter(this.g);
        ++this.e;
        this.f = true;
        new j(this.d, this.b, new com.ss.android.newmedia.feedback.n(this.h, v2, v2, -1, ((long) this.e), 5)).start();
    }

    public final View onCreateView(LayoutInflater arg3, ViewGroup arg4, Bundle arg5) {
        View v1 = arg3.inflate(com.ss.android.article.browser.R.layout.fp, arg4, false);
        this.i = v1.findViewById(com.ss.android.article.browser.R.id.listview);
        this.j = v1.findViewById(com.ss.android.article.browser.R.id.progressbar);
        return v1;
    }

    public final void onResume() {
        long v2 = 0;
        super.onResume();
        if (!this.a) {
            this.a = false;
        } else if (this.f) {
            this.a = false;
        } else {
            ++this.e;
            this.f = true;
            this.j.setVisibility(View.GONE);
            long v4 = this.c == null || this.c.size() <= 0 ? v2 : ((com.ss.android.newmedia.feedback.g) this.c.get(this.c.size() - 1)).a;
            new j(this.d, this.b, new com.ss.android.newmedia.feedback.n(this.h, v2, v4, -1, ((long) this.e), 3)).start();
            this.a = false;
        }
    }
}

